package com.wcity.manage.dao.mapper;

import com.wcity.manage.dao.dal.BaseMapper;
import com.wcity.manage.dao.dal.model.PageModel;
import com.wcity.manage.dao.model.Block;
import com.wcity.manage.dao.model.Register;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Created by jn on 2016/12/10.
 * 注册用户dao
 */
@Repository
public interface RegisterMapper extends BaseMapper<Register,Serializable> {

    /**
     * 重置密码
     * @param pwd
     * @param id
     * @return
     */
    @Update(" update td_register set password = #{pwd} where id = #{id} ")
    int resetPwd(@Param("pwd")String pwd,@Param("id")int id);

    /**
     * 手机查找用户
     * @param phone
     * @return
     */
    @Select(" select id,phone,password,token,expire_time from td_register where phone = #{phone} ")
    Register findByPhone(String phone);

    /**
     * 获取小区下入住人数
     * @param blockId
     * @return
     */
    @Select("select count(1) from td_register where block_id = #{block_id}")
    int countByBlock(int blockId);

    /**
     * 获取token
     * @param registerId
     * @param token
     * @return
     */
    Register findToken(@Param("registerId")int registerId, @Param("token")String token);

    /**
     * 清除token
     * @param registerId
     * @return
     */
    @Update(" update td_register set token = '',expire_time = null where id = #{id} ")
    int deleteByRegisterId(@Param("id")int registerId);

    /**
     * 更新token
     * @param uuid
     * @param registerId
     * @return
     */
    @Update(" update td_register set token = #{uuid},expire_time = NOW() where id = #{registerId} ")
    int authToken(@Param("uuid") String uuid,@Param("registerId") int registerId);
}
